package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 购物车相关接口
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "购物车相关接口")
@Slf4j
public class ShoppingCartController {
@Autowired
private ShoppingCartService shoppingCartService;
    /**
     * 接口描述：添加购物车
     * 请求参数：ShoppingCartDTO
     *      {
     *          "dishFlavor": "string",
     *          "dishId": 0,
     *          "setmealId": 0
     *      }
     * 请求方式：POST
     * 请求地址：/user/shoppingCart/add
     * 响应结果：Result
     * @return Result
     */
    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.add(shoppingCartDTO);
        return Result.success();
    }
    /**
     * 接口描述：查看购物车
     * 请求方式：GET
     * 请求地址：/user/shoppingCart/list
     * 响应结果：Result<list<ShoppingCart>>
     * @return Result
     * 请求参数：无
     */
    @GetMapping("/list")
    public Result<List<ShoppingCart>> list() {
        List<ShoppingCart> list = shoppingCartService.showShoppingCart();
        return Result.success(list);
    }
    /**
     * 接口描述：清空购物车
     * 请求方式：DELETE
     * 请求地址：/user/shoppingCart/clean
     * 响应结果：Result
     * @return Result
     * 请求参数：无
     */
    @DeleteMapping("/clean")
    public Result cleanShoppingCart() {
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }
    /**
     * 接口描述：删除购物车中一个商品
     * 请求方式：POST
     * 请求地址：/user/shoppingCart/sub
     * 响应结果：Result
     * @return Result
     * 请求参数：ShoppingCartDTO
     *         {
     *      "dishFlavor": "string",
     *      "dishId": 0,
     *      "setmealId": 0
     *          }
     */
    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        shoppingCartService.sub(shoppingCartDTO);
        return Result.success();
    }
}
